import java.util.Scanner;

public class O_1084 {
    public static void main(String[] args) {
        Scanner sc =  new Scanner(System.in);
        int v = sc.nextInt(),n = sc.nextInt();
        int[] value = new int[n];
        int[][] dp = new int[n+1][v+1];
        for (int i = 0; i < n; i++) {
            value[i] = sc.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= v; j++) {
                dp[i][j] = dp[i-1][j];
                if (value[i-1]<=j){
                    dp[i][j] = Math.max(dp[i-1][j],value[i-1]+dp[i-1][j-value[i-1]]);
                }
            }
        }
        System.out.println(v-dp[n][v]);
    }
}
